package com.jk.controller;

import com.jk.dto.TbSubject;
import com.jk.pojo.PagedResponse;
import com.jk.pojo.ResponseResult;
import com.jk.service.TbSubjectServiceFegin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @author yzf
 * @version 1.0
 * @description: TODO
 * @date 2024/12/11 20:23
 */
@Api(tags = "学科管理")
@Slf4j
@RestController
@RequestMapping(value = "subject")
public class TbSubjectController {

    @Autowired
    private TbSubjectServiceFegin tbSubjectServiceFegin;

    @ApiOperation(value = "分页查询",httpMethod = "POST")
    @PostMapping(value = "findSubjectList")
    public ResponseResult<PagedResponse<TbSubject>> findSubjectList(@RequestBody TbSubject tbSubject, @RequestParam(value = "pageNum") Integer pageNum, @RequestParam(value = "pageSize") Integer pageSize) {
        return new ResponseResult(200,"查询成功",tbSubjectServiceFegin.findSubjectList(tbSubject,pageNum,pageSize));
    }

    @ApiOperation(value = "删除",httpMethod = "DELETE",notes = "删除")
    @DeleteMapping("delSubjectById")
    public ResponseResult delSubjectById(@RequestParam Integer id) {

        try {
            tbSubjectServiceFegin.delSubjectById(id);
            return new ResponseResult<>(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(500,"删除失败");

        }
    }
    @ApiOperation(value = "新增",httpMethod = "POST",notes = "新增")
    @RequestMapping("addSubject")
    public ResponseResult addSubject(@RequestBody TbSubject tbSubject) {
        try {
            tbSubjectServiceFegin.addSubject(tbSubject);
            return new ResponseResult<>(200,"新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(500,"新增失败");
        }
    }

    @ApiOperation(value = "回显",httpMethod = "GET",notes = "回显")
    @RequestMapping("getSbjectById")
    public ResponseResult<TbSubject> getSbjectById(@RequestParam Integer id) {
        return new ResponseResult<>(200,"回显成功", tbSubjectServiceFegin.getSubjectById(id));
    }

    /**
     * @description: 修改
     * @param: [sysUser]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author yzf
     * @date: 2024/11/5 20:22
     */

    @ApiOperation(value = "修改",httpMethod = "PUT",notes = "修改")
    @RequestMapping("upSubject")
    public ResponseResult upSubject(@RequestBody TbSubject tbSubject) {
        try {
            tbSubjectServiceFegin.upSubject(tbSubject);
            return new ResponseResult<>(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(500,"修改失败");

        }
    }}
